package com.flyme.module.base.client.enums;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.flyme.core.base.supper.entity.EntityMap;
import lombok.Getter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工作年限枚举
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
public enum WorkingYearEnum implements IEnum {
    underThree("WY_01", "15年以上"),
    threeToEight("WY_02", "3年至8年"),
    eightToFifteen("WY_03", "8年至15年"),
    overFifteen("WY_04", "3年以下"),
    sixMonth("WY_05", "6个月以内");
    public String text;
    @EnumValue
    public String code;

    private WorkingYearEnum(String code, String text) {
        this.code = code;
        this.text = text;
    }

    private WorkingYearEnum(String code) {
        this.text = getText(code);
        this.code = code;
    }

    public static String getText(String code) {
        String v = "";
        for (WorkingYearEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.text;
                break;
            }
        }
        return v;
    }

    public static Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>();
        for (WorkingYearEnum professionEnum : values()) {
            map.put(professionEnum.code, professionEnum.text);
        }
        return map;
    }

    public static List<EntityMap> getList() {
        List<EntityMap> list = new ArrayList<>();
        for (WorkingYearEnum professionEnum : values()) {
            EntityMap map = new EntityMap();
            map.put("text", professionEnum.text);
            map.put("name", professionEnum.name());
            list.add(map);
        }
        return list;
    }

    public static List<EntityMap> getList2() {
        List<EntityMap> list = new ArrayList<>();
        for (WorkingYearEnum professionEnum : values()) {
            EntityMap map = new EntityMap();
            map.put("text", professionEnum.text);
            map.put("name", professionEnum.name());
            map.put("code", professionEnum.code);
            list.add(map);
        }
        return list;
    }

    public static WorkingYearEnum getEnum(String code) {
        for (WorkingYearEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                return accountTypeEnum;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        //System.out.println(WorkingYearEnum.sixMonth.code);
        System.out.println(DateUtil.now());
    }

    @Override
    public Serializable getValue() {
        return this.code;
    }
}
